package com.whfc.ms.api.uni.controller;

import com.whfc.common.base.BaseController;
import com.whfc.common.result.PageData;
import com.whfc.common.result.Result;
import com.whfc.common.result.ResultUtil;
import com.whfc.common.util.SessionAttr;
import com.whfc.fuum.entity.SysUser;
import com.whfc.ms.api.uni.service.MsCarWashDeviceService;
import com.whfc.uni.entity.CarWashDevice;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/ms/api/carWashDevice")
public class CarWashDeviceController extends BaseController {

    @Autowired
    private MsCarWashDeviceService msCarWashDeviceService;

    @GetMapping(value = "/list", params = {"pageNum", "pageSize"})
    public Result deviceList(@SessionAttribute(SessionAttr.MS_USER) SysUser user,
                             @RequestParam("pageNum") Integer pageNum,
                             @RequestParam("pageSize") Integer pageSize,
                             @RequestParam("deptId") Integer deptId,
                             @RequestParam(value = "name", required = false) String name,
                             @RequestParam(value = "type", required = false) Integer type) {
        logger.info("获取车辆冲洗设备列表分页：loginer:{},pageNum:{},pageSize:{},deptId:{}",
                user.getUsername(), pageNum, pageSize, deptId);
        PageData<CarWashDevice> pageData = msCarWashDeviceService.listPage(pageNum, pageSize,deptId,name,type);
        return ResultUtil.success(pageData);
    }

    @GetMapping(value = "/list")
    public Result deviceList(@SessionAttribute(SessionAttr.MS_USER) SysUser user,
                             @RequestParam("deptId") Integer deptId,
                             @RequestParam(value = "name", required = false) String name,
                             @RequestParam(value = "type", required = false) Integer type
    ) {
        logger.info("获取车辆冲洗设备列表：loginer:{},deptId:{}",
                user.getUsername(),  deptId);
        List<CarWashDevice> list = msCarWashDeviceService.list(deptId,name,type);
        return ResultUtil.success(list);
    }

    @PostMapping("/add")
    public Result add(@SessionAttribute(SessionAttr.MS_USER) SysUser user,
                      @RequestBody CarWashDevice request) {
        logger.info("添加车辆冲洗设备：loginer:{},request:{}", user.getUsername(), request.toString());
        msCarWashDeviceService.add(request);
        return ResultUtil.success();
    }

    @PostMapping("/edit")
    public Result edit(@SessionAttribute(SessionAttr.MS_USER) SysUser user,
                       @RequestBody CarWashDevice request) {
        logger.info("编辑车辆冲洗设备：loginer:{},request:{}", user.getUsername(), request.toString());
        msCarWashDeviceService.edit(request);
        return ResultUtil.success();
    }

    @PostMapping("/del/{id}")
    public Result del(@SessionAttribute(SessionAttr.MS_USER) SysUser user,
                      @PathVariable("id") Integer id) {
        logger.info("删除车辆冲洗设备：loginer:{},id:{}", user.getUsername(), id);
        msCarWashDeviceService.del(id);
        return ResultUtil.success();
    }

}
